//
//  OrderManageViewController.m
//  PrintPort
//
//  Created by 华谕 on 2017/11/28.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "OrderManageViewController.h"
#import "MyOrderModel.h"
#import "SYPasswordView.h"
#import "RetrievePasswordViewController.h"
#import "RSA.h"
#import "ExpressInfoViewController.h"
#import "BuyBackPasswordViewController.h"
#import "FeedBackViewController.h"

static NSString *cellPath = @"OrderManageCell";
@interface OrderManageViewController ()<UITableViewDelegate,UITableViewDataSource,PayPassWordDelegate>
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSMutableArray *orderAry;
@property (nonatomic, assign)NSInteger page;
@property (nonatomic, strong)UIView *topView;
@property (nonatomic, strong)UIView *bottonLine;
@property (nonatomic, strong)NSDictionary *orderStatusDic;
@property (nonatomic, strong)SYPasswordView *pasView;
@property (nonatomic, strong)UIView *payPassView;
@property (nonatomic, assign)NSInteger indexPathRow;
@property (nonatomic, strong)NSString *orderID;
@property (nonatomic, assign)NSInteger passType;
@property (nonatomic, strong)NSString *trnoID;
@property (nonatomic, assign)BOOL isPay;

@end

@implementation OrderManageViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = YES;
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(Successnotice:) name:@"PaySuccess" object:nil];
    [self loadNewHeaderData];
}


- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PaySuccess" object:nil];
    
}

- (void)Successnotice:(NSNotification *)center
{
    if (!_isPay)
    {
        _isPay = YES;
        [self loadNewHeaderData];
        
    }
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _orderStatusDic = @{@"100":@"待付款",
                        @"110":@"待发货",
                        @"120":@"待收货",
                        @"130":@"退款",
                        @"200":@"已完成",
                        @"300":@"已取消"
                        };
    _page = 0;
    _passType = 0;
    _trnoID = @"";
    _orderAry = [NSMutableArray arrayWithCapacity:0];
    [self creatUI];
    [self loadNewHeaderData];
}

- (void)creatUI
{
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = YES;
    self.navigationItem.title = @"我的订单";
    self.view.backgroundColor = BacksColor;
    NSArray *titAry = @[@"全部",@"待付款",@"待发货",@"待收货",@"已完成",@"退款"];
    self.topView = [[UIView alloc] initWithFrame:CGRectMake(0, STA_NAV_HEIGHT, SCREEN_WIDTH, 40*displaywidth)];
    _topView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_topView];
    UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 39*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
    lineview.backgroundColor = LinesColor;
    [_topView addSubview:lineview];
    CGFloat W = SCREEN_WIDTH/6;
    for (int i = 0; i < titAry.count; i++)
    {
        UIButton *titBtn = [ZCControl createButtonWithFrame:CGRectMake(W*i, 5*displaywidth, W, 30*displaywidth) ImageName:nil Target:self Action:@selector(closeTypeAction:) Title:titAry[i] Font:13.0];
        titBtn.tag = 10+i;
        [titBtn setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
        if (i == _orderType)
        {
            [titBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
        }
        titBtn.backgroundColor = [UIColor clearColor];
        [_topView addSubview:titBtn];
    }
    UIButton *btn = (UIButton *)[_topView viewWithTag:_orderType+10];
    self.bottonLine = [[UIView alloc] initWithFrame:CGRectMake(btn.frame.origin.x+btn.frame.size.width/2-15*displaywidth, 38.5*displaywidth, 30*displaywidth, 1.5*displaywidth)];
    _bottonLine.backgroundColor = ThemeColor;
    [_topView addSubview:_bottonLine];
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, STA_NAV_HEIGHT+40*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-40*displaywidth-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.backgroundColor = BacksColor;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableview];
    self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewHeaderData)];
    self.tableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreFootData)];
    self.tableview.mj_footer.automaticallyHidden = YES;
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
}

- (void)loadNewHeaderData
{
    _page = 0;
    [self requestOrderList:_TypeString];
}

- (void)loadMoreFootData
{
    _page++;
    [self requestOrderList:_TypeString];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _orderAry.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_orderAry.count > 0)
    {
        MyOrderModel *model = _orderAry[indexPath.row];
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 35*displaywidth, 60*displaywidth, 60*displaywidth) ImageName:@""];
        if (model.productImgUrl.length > 0)
        {
            [imgView sd_setImageWithURL:[NSURL URLWithString:model.productImgUrl]];
        }
        imgView.contentMode = UIViewContentModeScaleAspectFill;
        imgView.layer.masksToBounds = YES;
        [cell.contentView addSubview:imgView];
        NSString *orderStatus = model.orderStatus;
        NSString *typeName = @"";
        if ([_orderStatusDic.allKeys containsObject:orderStatus])
        {
            typeName = [_orderStatusDic objectForKey:orderStatus];
            if ([orderStatus integerValue]== 130)
            {
                NSString *refundStatus = model.refundStatus;
                NSDictionary *tkTypeDic = @{@"0":@"未申请",
                                            @"1":@"退款中",
                                            @"2":@"退款完成",
                                            @"3":@"退款失败"
                                            };
                if ([tkTypeDic.allKeys containsObject:refundStatus])
                {
                    typeName = [tkTypeDic objectForKey:refundStatus];
                }
            }
        }
        UILabel *orderTypeLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-115*displaywidth, 0, 100*displaywidth, 25*displaywidth) Font:13.0 Text:typeName Color:ThemeColor];
        orderTypeLab.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:orderTypeLab];
        
        UILabel *proNameLab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 30*displaywidth, SCREEN_WIDTH-115*displaywidth, 25*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"%@",model.productName] Color:RGB(77, 77, 77)];
        proNameLab.lineBreakMode = NSLineBreakByTruncatingTail;
        [cell.contentView addSubview:proNameLab];
        
        UILabel *shopTypeLab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 60*displaywidth, SCREEN_WIDTH-115*displaywidth, 45*displaywidth) Font:10.0 Text:[NSString stringWithFormat:@"%@",model.productSizeDetail] Color:RGB(128, 128, 128)];
        proNameLab.lineBreakMode = NSLineBreakByTruncatingTail;
        proNameLab.adjustsFontSizeToFitWidth = NO;
        [cell.contentView addSubview:shopTypeLab];
        
        UILabel *tongJiLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 105*displaywidth, SCREEN_WIDTH-30*displaywidth, 25*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"共%@件商品  合计：￥%@元",model.buySizeTol,model.payPrice] Color:RGB(77, 77, 77)];
        tongJiLab.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:tongJiLab];
        if ([model.area integerValue] != 4)
        {
            tongJiLab.text = [NSString stringWithFormat:@"共%@件商品  合计：￥%@元 + %@积分",model.buySizeTol,model.payPrice,model.payIntegral];
        }
        UIView *lineOne = [[UIView alloc] initWithFrame:CGRectMake(0, 130*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineOne.backgroundColor = BacksColor;
        [cell.contentView addSubview:lineOne];
        if ([orderStatus integerValue] == 130 || [orderStatus integerValue] == 300)
        {
            lineOne.frame = CGRectMake(0, 130*displaywidth, SCREEN_WIDTH, 10*displaywidth);
        }
        else
        {
            NSString *leftName = @"";
            NSString *rightName = @"";
            if ([orderStatus integerValue] == 100)
            {
                leftName = @"取消订单";
                rightName = @"立即付款";
            }
            else if ([orderStatus integerValue] == 110)
            {
                leftName = @"取消订单";
                rightName = @"催促发货 ";
            }
            else if ([orderStatus integerValue] == 120)
            {
                leftName = @"查看物流";
                rightName = @"确认收货 ";
            }
            
            UIButton *leftBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-170*displaywidth, 135*displaywidth, 70*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(leftBtnAction:) Title:leftName Font:11.0];
            leftBtn.backgroundColor = [UIColor whiteColor];
            [leftBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
            leftBtn.layer.cornerRadius = 3;
            leftBtn.layer.masksToBounds = YES;
            leftBtn.layer.borderWidth = 1;
            leftBtn.layer.borderColor = ThemeColor.CGColor;
            leftBtn.tag = 500+indexPath.row;
            [cell.contentView addSubview:leftBtn];
            UIButton *rightBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-87*displaywidth, 135*displaywidth, 70*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(rightBtnAction:) Title:rightName Font:11.0];
            rightBtn.backgroundColor = ThemeColor;
            rightBtn.layer.cornerRadius = 3;
            rightBtn.layer.masksToBounds = YES;
            [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            rightBtn.tag = 2000+indexPath.row;
            [cell.contentView addSubview:rightBtn];
            if ([orderStatus integerValue] == 200)
            {
                leftBtn.hidden = YES;
                rightBtn.hidden = YES;
                UIButton *tuiKuanBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-67*displaywidth, 135*displaywidth, 50*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(tuiKuanBtnAction:) Title:@"退款" Font:11.0];
                tuiKuanBtn.backgroundColor = [UIColor whiteColor];
                [tuiKuanBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
                tuiKuanBtn.layer.cornerRadius = 3;
                tuiKuanBtn.layer.masksToBounds = YES;
                tuiKuanBtn.layer.borderWidth = 1;
                tuiKuanBtn.layer.borderColor = ThemeColor.CGColor;
                tuiKuanBtn.tag = 3500+indexPath.row;
                [cell.contentView addSubview:tuiKuanBtn];
            }
            UIView *lineTwo = [[UIView alloc] initWithFrame:CGRectMake(0, 160*displaywidth, SCREEN_WIDTH, 5*displaywidth)];
            lineTwo.backgroundColor = BacksColor;
            [cell.contentView addSubview:lineTwo];
        }
    }
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (void)leftBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-500;
    MyOrderModel *model = _orderAry[index];
    NSString *orderStatus = model.orderStatus;
    if ([orderStatus integerValue] == 100 || [orderStatus integerValue] == 110)
    {
        WEAKSELF;
        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"您将要取消该订单" message:@"" preferredStyle:UIAlertControllerStyleAlert];
        [alertVc addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        [alertVc addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [weakSelf requestOrderCancel:model.ID IndexRow:index];
        }]];
        [self presentViewController:alertVc animated:YES completion:nil];
    }
    else if ([orderStatus integerValue] == 120)
    {
        ExpressInfoViewController *vc = [[ExpressInfoViewController alloc] init];
        vc.orderModel = model;
        [self.navigationController pushViewController:vc animated:YES];
    
    }
    
}

- (void)rightBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-2000;
    MyOrderModel *model = _orderAry[index];
    NSString *orderStatus = model.orderStatus;
    if ([orderStatus integerValue] == 120)
    {
        _indexPathRow = index;
        _orderID = model.ID;
        _passType = 1;
        [self creatPayPassWordView];
    }
    else if ([orderStatus integerValue] == 100)
    {
        _passType = 0;
        _indexPathRow = index;
        _trnoID = model.tradeNo;
        WEAKSELF;
        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"选择支付方式" message:nil preferredStyle:UIAlertControllerStyleAlert];
        [alertVc addAction:[UIAlertAction actionWithTitle:@"微信支付" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            PayManager *manage = [PayManager sharePayManager];
            [manage startNewPayRequest:0 Pid:weakSelf.trnoID];
        }]];
        [alertVc addAction:[UIAlertAction actionWithTitle:@"支付宝" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            PayManager *manage = [PayManager sharePayManager];
            [manage startNewPayRequest:1 Pid:weakSelf.trnoID];
        }]];
        
        [alertVc addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        [self presentViewController:alertVc animated:YES completion:nil];

    }
    else if ([orderStatus integerValue] == 110)
    {
        [self requestOrderUrgeDeliver:s_str(model.ID)];
    }
    
}


- (void)tuiKuanBtnAction:(UIButton *)btn
{
    NSInteger index = btn.tag-3500;
    MyOrderModel *model = _orderAry[index];
    FeedBackViewController *vc = [[FeedBackViewController alloc] init];
    vc.pladerStr = @"退款原因";
    vc.titleStr = @"退款申请";
    vc.isTuiKuan = YES;
    vc.orderID = model.ID;
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)creatPayPassWordView
{
    if (!self.payPassView)
    {
        self.payPassView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _payPassView.backgroundColor = RGBA(0, 0, 0, 0.5);
        [sharedDelegate.window addSubview:_payPassView];
        UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(0, 230*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-230*displaywidth)];
        secondView.backgroundColor = RGB(242, 242, 242);
        [_payPassView addSubview:secondView];
        UILabel *titleLabel = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH/2-80*displaywidth, 0, 160*displaywidth, 44*displaywidth) Font:15.0 Text:@"请输入密码" Color:RGB(77, 77, 77)];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [secondView addSubview:titleLabel];
        UIButton *contactBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-60*displaywidth, 0, 44*displaywidth, 44*displaywidth) ImageName:@"chacha" Target:self Action:@selector(contactAction) Title:nil Font:13.0];
        contactBtn.backgroundColor = [UIColor clearColor];
        [secondView addSubview:contactBtn];
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 44*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineview.backgroundColor = RGB(210, 210, 210);
        [secondView addSubview:lineview];
        //        UILabel *moneyLabel = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 55*displaywidth, SCREEN_WIDTH-30*displaywidth, 25*displaywidth) Font:15.0 Text:@"充值金额 2000" Color:RGB(77, 77, 77)];
        //        moneyLabel.textAlignment = NSTextAlignmentCenter;
        //        [secondView addSubview:moneyLabel];
        self.pasView = [[SYPasswordView alloc] initWithFrame:CGRectMake(15*displaywidth, 90*displaywidth, SCREEN_WIDTH-30*displaywidth, 44*displaywidth)];
        _pasView.delegate = self;
        [secondView addSubview:_pasView];
        UIButton *forgotBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-115*displaywidth, 150*displaywidth, 100*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(FindPassword) Title:@"忘记密码" Font:13.0];
        [forgotBtn setTitleColor:RGB(255, 111, 28) forState:UIControlStateNormal];
        [secondView addSubview:forgotBtn];
    }
    _payPassView.hidden = NO;
    [_pasView.textField becomeFirstResponder];
}
- (void)shuruSuccessValue:(NSString *)value
{
    [self requestPublicKey:value];
    NSLog(@"密码-----%@",value);
}

//找回密码
- (void)FindPassword
{
    _payPassView.hidden = YES;
    [self.pasView endEditing:YES];
    [self.pasView clearUpPassword];
    BuyBackPasswordViewController *vc = [[BuyBackPasswordViewController alloc] init];
    vc.isPayPass = YES;
    vc.passType = @"4";
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)contactAction
{
    _payPassView.hidden = YES;
    [self.pasView endEditing:YES];
    [self.pasView clearUpPassword];
}

- (void)closeTypeAction:(UIButton *)btn
{
    _orderType = btn.tag-10;
    NSArray *typeAry = @[@"",@"100",@"110",@"120",@"200",@"130"];
    _TypeString = typeAry[_orderType];
    _page = 0;
    [self requestOrderList:_TypeString];
    for (id v in _topView.subviews)
    {
        if ([v isKindOfClass:[UIButton class]])
        {
            [v setTitleColor:RGB(77, 77, 77) forState:UIControlStateNormal];
        }
    }
    [btn setTitleColor:ThemeColor forState:UIControlStateNormal];
    self.bottonLine.frame = CGRectMake(btn.frame.origin.x+btn.frame.size.width/2-15*displaywidth, 38.5*displaywidth, 30*displaywidth, 1.5*displaywidth);
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_orderAry.count > 0)
    {
        MyOrderModel *model = _orderAry[indexPath.row];
        NSString *orderStatus = model.orderStatus;
        if ([orderStatus integerValue] == 130 || [orderStatus integerValue] == 300)
        {
            return 140*displaywidth;
        }
        return 165*displaywidth;
    }
    return 165*displaywidth;
}



- (void)requestOrderList:(NSString *)typeStr
{
    WEAKSELF;
    NSDictionary *dic = @{@"orderStatus":typeStr,
                          @"page":[NSString stringWithFormat:@"%ld",_page]
                          };
    [HYBaseHandler requestOrderListParmers:dic Success:^(id obj)
    {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
        if ([obj server_Getcodecheck])
        {
            NSArray *allAry = [MyOrderModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
            if (_page == 0)
            {
                [weakSelf.orderAry removeAllObjects];
            }
            [weakSelf.orderAry addObjectsFromArray:allAry];
            
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            _isPay = NO;
            [weakSelf.tableview reloadData];
            if (weakSelf.page == 0)
            {
                [weakSelf.tableview setContentOffset:CGPointMake(0,0) animated:NO];
            }
        });
       
    } failed:^(NSError *error) {
        [weakSelf.tableview.mj_header endRefreshing];
        [weakSelf.tableview.mj_footer endRefreshing];
    }];
}

//取消订单
- (void)requestOrderCancel:(NSString *)orderId IndexRow:(NSInteger)index
{
    WEAKSELF;
    NSDictionary *dic = @{@"orderMasterId":orderId};
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [HYBaseHandler requestOrderCancelParmers:dic Success:^(id obj)
    {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if ([obj server_Getcodecheck])
        {
            if (weakSelf.orderAry.count > index)
            {
                [weakSelf.orderAry removeObjectAtIndex:index];
                [LTools showMBProgressWithText:@"取消订单成功" addToView:weakSelf.view];
            }
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            
            [weakSelf.tableview reloadData];
        });
    } failed:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];

    }];
}

- (void)requestWalletPay:(NSString *)pass
{
    WEAKSELF;
    NSDictionary *dic = @{@"tradeNo":_trnoID,
                          @"password":pass
                          };
    [HYBaseHandler requestWalletPayParmers:dic Success:^(id obj)
     {
         [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
         if ([obj server_Getcodecheck])
         {
             [LTools showMBProgressWithText:@"支付成功" addToView:sharedDelegate.window];
             if (weakSelf.orderAry.count > _indexPathRow)
             {
                 [weakSelf.orderAry removeObjectAtIndex:_indexPathRow];
                 
             }
             dispatch_async(dispatch_get_main_queue(), ^{
                 [weakSelf.tableview reloadData];
                 [self contactAction];
             });
         }
         else
         {
             [self.pasView clearUpPassword];
             [LTools showMBProgressWithText:obj[@"msg"] addToView:sharedDelegate.window];
         }
     } failed:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
     }];
}


- (void)requestPublicKey:(NSString *)passWorld
{
    WEAKSELF;
    [MBProgressHUD showHUDAddedTo:sharedDelegate.window animated:YES];
    [HYBaseHandler requestPublicKeyParmers:nil Success:^(id obj)
    {
        if ([obj server_Getcodecheck])
        {
            NSString *publicKey = obj[@"data"];
            NSString *sourceStr = passWorld;
            NSString *encryptStr = [RSA encryptString:sourceStr publicKey:publicKey];
            if (weakSelf.passType == 1)
            {
                [weakSelf requestOrderSoure:encryptStr];
            }
            else
            {
                [weakSelf requestWalletPay:encryptStr];
            }
            
            
        }
        else
        {
            [self.pasView clearUpPassword];
            [LTools showMBProgressWithText:obj[@"msg"] addToView:sharedDelegate.window];
            [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
        }
    } failed:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
    }];
}

//确认收货
- (void)requestOrderSoure:(NSString *)passWord
{
    WEAKSELF;
    NSDictionary *dic = @{@"orderMasterId":_orderID,
                          @"password":passWord
                          };
    [HYBaseHandler requestOrderSoureParmers:dic Success:^(id obj)
    {
        [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];

        if ([obj server_Getcodecheck])
        {
            if (weakSelf.orderAry.count > _indexPathRow)
            {
                [weakSelf.orderAry removeObjectAtIndex:_indexPathRow];
                
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [weakSelf.tableview reloadData];
                [self contactAction];
            });
        }
        else
        {
            [self.pasView clearUpPassword];
            [LTools showMBProgressWithText:obj[@"msg"] addToView:sharedDelegate.window];
        }
        
    } failed:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];

    }];
}

- (void)requestOrderUrgeDeliver:(NSString *)orderID
{
    WEAKSELF;
    NSDictionary *dic = @{@"orderMasterId":orderID};
    [HYBaseHandler requestOrderUrgeDeliverParmers:dic Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             [LTools showMBProgressWithText:@"提醒成功" addToView:weakSelf.view];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
